package com.tinyseed.emcp.api.productionRule.rest;

import com.tinyseed.emcp.api.productionRule.bean.ReductionInputDTO;
import com.tinyseed.emcp.api.productionRule.service.ReductionService;
import com.tinyseed.emcp.api.productionRule.transfer.ReductionTransfer;
import com.tinyseed.hmxx.common.base.BaseController;
import com.tinyseed.hmxx.common.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/reduction")
@Api("减排方案管理接口")
public class ReductionController extends BaseController {

    @Autowired
    ReductionService reductionService;

    /**
     * 得到分页信息
     */
    @RequestMapping(value = "/page")
    @ResponseBody
    public ResponseEntity page(int size, int current, Long level, String startCreateTime, String endCreateTime) {
        // 使用 Db 的 template 方法
        ReductionInputDTO reductionInputDTO = new ReductionInputDTO();
        reductionInputDTO.setLevel(level);
        reductionInputDTO.setStartCreateTime(startCreateTime);
        reductionInputDTO.setEndCreateTime(endCreateTime);
        PageData result = reductionService.page(size, current, reductionInputDTO);
        return new ResponseEntity<>(result,HttpStatus.OK);


    }

    @GetMapping(value = "list")
    @ApiOperation("分页查询")
    public ResponseEntity list(ReductionInputDTO request, int size, int current) {
        return new ResponseEntity<>(reductionService.getList(request, size, current),HttpStatus.OK);


    }

    /**
     * 保存
     */
    @PostMapping(value = "/save")
    @ResponseBody
    public ResponseEntity save(ReductionInputDTO reductionInputDTO) {
        return new ResponseEntity<>(reductionService.save(ReductionTransfer.INSTANCE.mapIn2Model(reductionInputDTO)),HttpStatus.OK);

    }
    /**
     * 删除
     */
    @PostMapping(value = "/delete")
    @ResponseBody
    public ResponseEntity delete(Long id) {
        reductionService.delete(id);
        return new ResponseEntity<>(HttpStatus.OK);

    }

    /**
     * 批量删除
     */
    @PostMapping(value = "/deleteBatch")
    @ResponseBody
    public ResponseEntity deleteBatch(Long[] ids) {
        reductionService.deleteBatch(ids);
        return new ResponseEntity<>(HttpStatus.OK);

    }

//    @PostMapping(value = "optionList")
//    @ResponseBody
//    public AjaxResult optionList(){
//        return AjaxResult.succeed(reductionService.getOptionList());
//    }

}
